package com.easylinkin.linkappapi.quality.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easylinkin.linkappapi.common.model.RequestModel;
import com.easylinkin.linkappapi.quality.dto.QualityActionRecordsDTO;
import com.easylinkin.linkappapi.quality.entity.QualityActionRecords;
import com.easylinkin.linkappapi.quality.service.QualityActionRecordsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

/**
 * @author: kan yuanfeng
 * @Date: 2023/04/04 11:42
 * @Description: 质量管理查阅记录管理
 */
@RestController
@RequestMapping("qualityActionRecords")
@Api(tags = "质量管理查阅记录管理")
public class QualityActionRecordsController {
  
  @Autowired
  private QualityActionRecordsService qualityActionRecordsService;

  /**
   * @Description: 增加质量管理查阅记录
   * @author kan yuanfeng
   * @date 2023/04/04 11:42
   */
  @PostMapping
  @ApiOperation("增加质量管理查阅记录")
  public RestMessage insert(@RequestBody QualityActionRecords qualityActionRecords){
    Assert.notNull(qualityActionRecords.getActionType(),"操作类型不能为空");
    qualityActionRecordsService.insert(qualityActionRecords);
    return RestBuilders.successBuilder().build();
  }

  /**
   * @Description: 根据id查询质量管理查阅记录详情
   * @author kan yuanfeng
   * @date 2023/04/04 11:42
   */
  @GetMapping("{id}")
  @ApiOperation("根据id查询质量管理查阅记录详情")
  public RestMessage findById(@PathVariable("id")Integer id) {
    Assert.notNull(id,"id不能为空");
    QualityActionRecordsDTO qualityActionRecordsDTO = qualityActionRecordsService.findById(id);
    return RestBuilders.successBuilder().data(qualityActionRecordsDTO).build();
  }

  /**
   * @Description: 根据条件，分页(不分页)查询
   * @author kan yuanfeng
   * @date 2023/04/04 11:42
   */
  @PostMapping("list")
  @ApiOperation("根据条件，分页(不分页)查询")
  public RestMessage queryListByPage(@RequestBody RequestModel<QualityActionRecords> requestModel){
    Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
    Assert.notNull(requestModel.getPage(), "page 不能为空");
    IPage<QualityActionRecordsDTO> record =  qualityActionRecordsService.queryListByPage(requestModel);
    return RestBuilders.successBuilder().data(record).build();
  }
}

